package com.example.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

public class MyReceiver extends BroadcastReceiver {



    private TextView tvInfo;
    public MyReceiver(){
    }

    public MyReceiver(TextView tvInfo) {
        this.tvInfo = tvInfo;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        switch (intent.getAction()){
            //如果接收到的广播类型是“收短信”
            case "android.provider.Telephony.SMS_RECEIVED":
                Log.i("info","MyReceiver接收到短信广播");
//                tvInfo.setText("MyReceiver接收到短信广播");
                break;
            case "example.custom.receiver":
                String info = intent.getStringExtra("info");
                Log.i("info","MyRecevier 接收到的信息："+info);
                //终止有序广播,高优先级广播可以终止广播的传播，则低级接收器不能接受有序广播
                abortBroadcast();//对普通广播无效
                break;
        }



    }
}